package com.hengtongxing.hejiayun.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.LinearLayout;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.DialogFragment;


import com.hengtongxing.hejiayun.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 划拨或分配给门店
 */
public class WXShareDialog extends DialogFragment {


    @BindView(R.id.ll_wechat)
    LinearLayout llWechat;
    @BindView(R.id.ll_wxcircle)
    LinearLayout llWxcircle;
    private Dialog dialog;
    private OnCallBackListener onCallBackListener;
    private Activity mActivity;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        initWindow();
        View view = inflater.inflate(R.layout.dialog_wx_share, null);
        ButterKnife.bind(this, view);
        mActivity = getActivity();
        initView();
        return view;
    }

    public static WXShareDialog newInstance() {
        WXShareDialog fragment = new WXShareDialog();
        return fragment;
    }

    public void setOnCallBackListener(OnCallBackListener onCallBackListener) {
        this.onCallBackListener = onCallBackListener;
    }

    //    初始化请求
    private void initView() {

    }

    //设置window属性
    private void initWindow() {
        //去掉dialog的标题
        dialog = this.getDialog();
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        dialog.setCanceledOnTouchOutside(true);
        dialog.setCancelable(true);
        Window window = dialog.getWindow();
        window.getDecorView().setPadding(0, 0, 0, 0);
        WindowManager.LayoutParams lp = window.getAttributes();
        lp.width = WindowManager.LayoutParams.MATCH_PARENT;
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        lp.gravity = Gravity.BOTTOM;
        window.getAttributes().windowAnimations = R.style.commomDialog;
        window.setAttributes(lp);
        window.setBackgroundDrawable(new ColorDrawable());
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
    }

    @OnClick({R.id.ll_wechat, R.id.ll_wxcircle, R.id.tv_cancel})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.ll_wechat:
                onCallBackListener.onCallBack(1);
                dismiss();
                break;
            case R.id.ll_wxcircle:
                onCallBackListener.onCallBack(2);
                dismiss();
                break;
            case R.id.tv_cancel:
                dismiss();
                break;
        }
    }


    public interface OnCallBackListener {
        void onCallBack(int type);
    }
}
